/* Table */
BelFrame									= {}

/* Initialization */
BelFrame.Initialize							= function( self, ... )
	
	/* Register as BelControl */
	BelControls.Register( self, DFrame, ... )
	
	/* General design */
	self.SplitDesign					= false
	self.IncrustBorder					= true
	self.CornerSizeRatio				= 0.025
	self.DropShadow						= true
	
	/* Derma overrides */
	self.Title							= "BelFrame"
	self.TitleFont						= "CenterPrintText"
	self:ShowCloseButton( false )
	DFrame.SetTitle( self, "" )
	
	/* Background colors */
	self:SetBackgroundColors(
		Color( 125, 125, 125, 200 ),
		Color( 150, 150, 150, 200 ),
		Color( 125, 125, 125, 200 )
	)
	
	/* Custom close button */
	self.CloseButton					= vgui.Create( "BelButton", self )
	self.CloseButton:SetText( "X" )
	self.CloseButton:SetSize( 20, 20 )
	self.CloseButton:SetPos( self:GetMaxWide() - 40, 10 )
	self.CloseButton:Initialize()
	self.CloseButton.OnMouseReleased	= function( cb )
		DEBUG:Msg( "Closing...", "CloseButton.OnMouseReleased" )
		BelControls.OnMouseReleased( cb )
		self:SetVisible( false )
	end
	self.CloseButton.IncrustBorder		= false
	self.CloseButton.CornerSizeRatio	= 0.3
	self.CloseButton.ShowHideFader:SetInDuration( 0.15 )
	self.CloseButton.ShowHideFader:SetOutDuration( 0.15 )
	
	/* Background colors of the close button */
	self.CloseButton:SetBackgroundColors(
		Color( 175, 10, 10, 200 ),
		Color( 225, 25, 25, 200 ),
		Color( 25, 10, 10, 200 )
	)
	
	/* BelControl hooks */
	BelControls.AddHook( "OnHidden", self, BelFrame.Closed )
end

/* Override Derma Init */
BelFrame.Init								= function( self )
	/* Prevents showing 'Untitled DFrame' above the title... */
end

/* Frame closing */
BelFrame.Close								= function( self )
	
	/* Debug output */
	DEBUG:Msg( "Closing frame.", "BelFrame.Close" )
	
	/* Start by hiding the frame */
	self:SetVisible( false )
end

/* Frame closed */
BelFrame.Closed								= function( self )
	
	/* Debug output */
	DEBUG:Msg( "Frame closed. Removing resources.", "BelFrame.Closed" )
	
	/* Dispose ourselves */
	self:Dispose()
	
	/* Close ourselves and our children */
	DFrame.Close( self )
end

/* Sets the title of the frame */
BelFrame.SetTitle							= function( self, title )
	DFrame.SetTitle( self, "" )
	self.Title								= tostring( title )
end

/* Gets the title of the frame */
BelFrame.GetTitle							= function( self )
	return self.Title
end

/* Paint over control */
BelFrame.PaintOver							= function( self )

	/* Only once initialized */
	if not self.IsRegistered then return end

	/* Get the current color */
	local fadeValue							= self.ShowHideFader:GetCurrentValue()
	local foreColor							= self:GetTextColor()
	local alpha								= math.min( foreColor.a, fadeValue.Alpha )

	/* Draw the title */
	local font = {}
	font["pos"] = { 8, 5 }
	font["color"] = Color( foreColor.r, foreColor.g, foreColor.b, alpha )
	font["text"] = self.Title
	font["font"] = self.TitleFont
	font["xalign"] = TEXT_ALIGN_LEFT
	font["yalign"] = TEXT_ALIGN_TOP
	draw.TextShadow( font, 2, alpha )
	
	/* Underline title */
	surface.SetDrawColor( 255, 255, 255, alpha )
	surface.DrawLine( 7, 25 + 2, string.len( self.Title ) * 10 - 1, 25 + 2 )
	surface.SetDrawColor( 0, 0, 0, alpha )
	surface.DrawLine( 8, 25 + 3, string.len( self.Title ) * 10, 25 + 3 )
end

/* Register VGUI */
vgui.Register( "BelFrame", BelFrame, "DFrame" )